package com.lvhr.example.consumer;

import com.lvhr.example.common.model.User;
import com.lvhr.example.common.service.UserService;
import com.lvhr.rpc.bootstrap.ConsumerBootstrap;
import com.lvhr.rpc.config.RpcConfig;
import com.lvhr.rpc.proxy.ServiceProxyFactory;
import com.lvhr.rpc.utils.ConfigUtils;

import java.util.Collections;

public class SpringBootConsumerExample {

    public static void main(String[] args) {
        // 服务提供者初始化
        RpcConfig rpc = ConfigUtils.loadConfig(RpcConfig.class,"rpc","", Collections.singletonList("properties"));
        ConsumerBootstrap.init(rpc);

        // 获取代理
        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("lv-rpc");
        // 调用
        User newUser = userService.getUser(user);
        if (newUser != null) {
            System.out.println(newUser.getName());
        } else {
            System.out.println("user == null");
        }
    }
}

